package com.hamster.crm.web;

import com.hamster.crm.pojo.CourseTask;
import com.hamster.crm.pojo.CourseTaskResult;
import com.hamster.crm.service.CourseTaskService;
import com.hamster.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Tarry
 * @create 2019/12/19 14:22
 */
@RestController
@RequestMapping("courseTask")
public class CourseTaskController {
    @Autowired
    private CourseTaskService courseTaskService;

    /**
     * 后台新增一条，课程任务。
     * @param courseTask
     * @return 状态码 200
     */
    @PostMapping("insert")
    public ResponseEntity<Void> insertCourseTask(@RequestBody CourseTask courseTask){
        courseTaskService.insertCourseTask(courseTask);
        return ResponseEntity.ok().build();
    }

    /**
     * 返回所有的 课程任务列表（添加课程页面）
     * @return
     */
    @GetMapping("listCourseTasks")
    public ResponseEntity<List<CourseTask>> listCourseTasks(){
        List<CourseTask> courseTaskList = courseTaskService.listCourseTasks();
        return ResponseEntity.ok(courseTaskList);
    }

    /**
     * 删除选中的课程任务
     * @param ids
     * @return 状态码 200
     */
    @PostMapping("delete")
    public ResponseEntity<Void> deleteCourseTask(@RequestBody List<String> ids){
        courseTaskService.deleteCourseTaskById(ids);
        return ResponseEntity.ok().build();
    }

    /**
     * 下发任务，改变课程任务的状态
     * @param ids
     * @return 状态码 200
     */
    @PostMapping("sendTask")
    public ResponseEntity<Void> updateCourseTaskState(@RequestBody List<String> ids) {
        courseTaskService.updateCourseTaskStateById(ids);
        return ResponseEntity.ok().build();
    }

//    以下内容为参课结果页面----------------------------------------------

    /**
     * 返回参课结果列表
     * @return List<CourseTaskResult> 状态码200
     */
    @GetMapping("listCourseTaskResults")
    public ResponseEntity<PageResult<CourseTaskResult>> listCourseTaskResults(
            @RequestParam(required=false) Integer pageSize,
            @RequestParam(required=false) Integer currentPage,
            @RequestParam(required = false)String title,
            @RequestParam(required = false)String participant
    ){
        PageResult<CourseTaskResult> resultList = courseTaskService.listCourseTaskResults(title,participant,currentPage,pageSize);

        return ResponseEntity.ok(resultList);
    }

    /**
     * 查询该员工的该任务的参课率
     * @param employeeId 员工id
     * @param taskId    参课任务id
     * @return
     */
    @GetMapping("resultDetails")
    public ResponseEntity<List<CourseTaskResult>> listTaskByEmployeeId(@RequestParam String employeeId,String taskId){

        List<CourseTaskResult> list = courseTaskService.listTaskByEmployeeId(employeeId,taskId);

        return ResponseEntity.ok(list);
    }



}
